
import React,{Suspense} from "react";
import {Redirect,Route} from 'react-router-dom';
import {AOne} from "../views/loopRoute/loop-child/AOne";

const renderRoute = (props) => {

    const {routes} = props;

    return (
        <>
            {routes.map((item,index)=>{
                const {redirect , exact,from,to,component:Component,path,children} = item;
                let config = {path};
                if (redirect) {
                    return <Redirect key={index} from={from} to={to} exact={exact}/>;
                }
                if (exact) {
                    config.exact = exact;
                }
                // if (children){
                //     config.children = children;
                // }
                return <Route key={index} {...config}  render={props=>{
                    return <>
                        <Suspense fallback={<>loading...</>}>
                            <Component {...props}/>
                        </Suspense>
                    </>
                }}/>
            })}
        </>
    )
}

export default renderRoute;